package org.ling.xuan.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
import org.ling.xuan.condition.LxCondition;
import org.ling.xuan.dao.LocalAddDao;
import org.ling.xuan.dialog.AddInfoDialog;
import org.ling.xuan.entity.mo.LocalAdd;

/**
 * 编辑当前修改信息
 *
 * @author liting50684
 * @date 2023/08/01
 */
public class LxEditCurAddAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        LocalAdd add = LocalAddDao.getCur();
        String od = add.getId();
        AddInfoDialog addInfoDialog = new AddInfoDialog(e.getProject(), true, add);
        if (addInfoDialog.showAndGet()) {
            add = addInfoDialog.getSetting();
            add.setId(od);
            LocalAddDao.updateCurAddSimple(add);
        }
    }

    @Override
    public void update(AnActionEvent e) {
        boolean enable = LxCondition.getInstance().checkEditCurrCondition(e);
        e.getPresentation().setEnabledAndVisible(enable);
    }
}
